<?php
/**
 * PHP Daycare
 *	config.php
 * @author Jason Butz
 * @version 0.0
 * @package PHPDaycare
 */
/**
 * This class contains the configuration variables most never needs to be accessed by the user
 * @package PHPDaycare
 */
class Config
{
	/**
	 * Database variables
	 * @access public
	 */
	/**	 
	 * @var string MySQL server address default is localhost
	 */
	public $db_host = 'localhost';
	/**
	 * @var string MySQL database to be used
	 */
	public $db_name = 'jb373';
	/**
	 * @var string MySQL user
	 */
	public $db_user = 'jb373';
	/**
	 * @var string MySQL user's password
	 */
	public $db_pass = 'password';
	
	/**
	 * @access public
	 * @var string Organization's name
	 */
	public $org_name = 'Test Organization';
	/**
	 * @var string
	 * @access public Path to the index.php file
	 */
	public $base_path = '/home/jb373/www_home/seniorproject/phpdaycare/trunk/';
}
/////////////////////////////////////////////////
//        DO NOT EDIT BELOW THIS LINE          //
/////////////////////////////////////////////////
$config = new Config();
/**
 * Database
 * Class for querying and connecting to the database
 * @package PHPDaycare
 */
class Database
{
	/**
	 * connect_db
	 * uses the variables in the config class to connect to the database
	 * @return integer MySQL resource
	 */
	public function connect_db()
	{
		$link = mysql_connect($GLOBALS['config']->db_host, $GLOBALS['config']->db_user, $GLOBALS['config']->db_pass);
		if (!$link)
		{
			die('Could not connect: ' . mysql_error());
		}
		
		$db = mysql_select_db( $GLOBALS['config']->db_name , $link);
		if (!$db)
		{
			die ('Can\'t use database : ' . mysql_error());
		}
		return $link;
	}
	/**
	 * query
	 * uses connect_db to run a query on the database
	 * @param string $sql
	 * @return integer MySQL resource
	 */
	public function query($sql)
	{
		$link = $this->connect_db();
		$result = mysql_query($sql, $link);
		if (!$result)
		{
			die('Invalid query: ' . mysql_error());
		}
		return $result;
	}
}

$db = new Database();

?>
